﻿using Downloader.Domain;
using Downloader.Domain.Contracts.Tasks;
using Downloader.Web.Controllers.Queries;
using System.Collections.Generic;
using System.Web.Mvc;
using Downloader.Web.Controllers.ViewModels;

namespace Downloader.Web.Controllers
{
    public class WebPartController : Controller
    {
        public ICategoryTasks CategoryTasks { get; set; }
        public IArticleContentQuery ArticleContentQuery { get; set; }
        public ICategoryListQuery CategoryListQuery { get; set; }

        public ActionResult Menu()
        {
            var categoryList = CategoryListQuery.GetMenu();
            return PartialView(categoryList);
        }
        public ActionResult Footer()
        {
            return PartialView(null);
        }

        public ActionResult Top()
        {
            return PartialView(null);
        }

        public ActionResult ProductTitleList(int categoryId, int topNumber)
        {
            var productList = ArticleContentQuery.GetTopNumber(categoryId, topNumber);
            var list = new List<ProductTitleListViewModel>();
            foreach (var pro in productList)
            {
                var temp = new ProductTitleListViewModel {Id = pro.Id, Title = pro.Title};
                list.Add(temp);
            }
            return PartialView(list);
        }

        public ActionResult ProductCategoryList(int[] categoryIds,int topNumber)
        {
            var list = new List<CategoryViewModel>();
            foreach (var categoryId in categoryIds)
            {
                var category = CategoryTasks.Get(categoryId);
                var temp = new CategoryViewModel(category);
                list.Add(temp);
            }
            return PartialView(list);
        }
    }

    

    public class ProductTitleListViewModel
    {
        public string Title { get; set; }
        public int Id { get; set; }
    }

}
